﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<CRM.Database.Model.Customers>" %>



<%@ Import Namespace="CRM.Database.Model" %>
<%@ Import Namespace="CRM.Resourses" %>


<% Html.DevExpress().GridView(settings =>
                                    {
                                        settings.Name = "gdCreditContidions";
                                        settings.KeyFieldName = "IdCreditCondition";
                                        settings.CallbackRouteValues =
                                            new { Controller = "Contracts", Action = "CustomerCreditConditionsPartialEdit", customerId = Model.IdCustomer };
                                        settings.SettingsPager.PageSize = 20;

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.LegalEntityName;
                                            column.FieldName = "IdLegalEntity";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {

                                                comboBoxProperties.DataSource = Model.LegalEntities;
                                                comboBoxProperties.TextField = "Name";
                                                comboBoxProperties.ValueField = "IdLegalEntity";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.CreditConditionType;
                                            column.FieldName = "IdCreditType";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;
                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new CreditTypesCollection();
                                                comboBoxProperties.DataSource =col.CreditTypesList ;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdCreditType";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.CreditConditionAmount;
                                            column.FieldName = "Amount";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Unit;
                                            column.FieldName = "IdUnit";

                                            column.ColumnType = MVCxGridViewColumnType.ComboBox;

                                            var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                                            if (comboBoxProperties != null)
                                            {
                                                var col = new UnitsCollection();
                                                comboBoxProperties.DataSource =
                                                    col.UnitsList;
                                                comboBoxProperties.TextField = "LocalizedName";
                                                comboBoxProperties.ValueField = "IdUnit";
                                                comboBoxProperties.ValueType = typeof(int);
                                            }
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.CalendarDaysQuantity;
                                            column.FieldName = "NumberOfDays";
                                        });

                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.StartDate;
                                            column.FieldName = "StartDate";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.EndDate;
                                            column.FieldName = "EndDate";
                                            column.ColumnType = MVCxGridViewColumnType.DateEdit;
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.Comments;
                                            column.FieldName = "Comments";
                                            column.ColumnType = MVCxGridViewColumnType.Memo;
                                        });


                                        settings.Columns.Add(column =>
                                        {
                                            column.Caption = Resourses.AdditionalContract;
                                            column.FieldName = "IdContract";
                                        });




                                        //Добавление редактирования
                                        settings.CommandColumn.Visible = true;
                                        settings.CommandColumn.NewButton.Visible = true;
                                        settings.CommandColumn.DeleteButton.Visible = true;
                                        settings.CommandColumn.EditButton.Visible = true;
                                        settings.SettingsBehavior.ConfirmDelete = true;
                                        settings.Settings.ShowFilterRow = true;
                                        settings.SettingsEditing.UpdateRowRouteValues = new { Controller = "Contracts", Action = "CustomerCreditConditionsPartialUpdate", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.AddNewRowRouteValues = new { Controller = "Contracts", Action = "CustomerCreditConditionsPartialAdd", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.DeleteRowRouteValues = new { Controller = "Contracts", Action = "CustomerCreditConditionsPartialDelete", customerId = Model.IdCustomer };
                                        settings.SettingsEditing.Mode = GridViewEditingMode.EditFormAndDisplayRow;


                                     
                                    }).Bind(Model.CreditConditions).GetHtml();
                                    
                                    
                                    %>